package cn.com.lsy.product.lepao.service.impl;

import cn.com.lsy.product.lepao.model.dao.LpDataTotalTblMapper;
import cn.com.lsy.product.lepao.model.dao.LpStoreDataTotalTblMapper;
import cn.com.lsy.product.lepao.model.entities.LpDataTotalTbl;
import cn.com.lsy.product.lepao.model.entities.LpDataTotalTblExample;
import cn.com.lsy.product.lepao.model.entities.LpStoreDataTotalTbl;
import cn.com.lsy.product.lepao.model.entities.LpStoreDataTotalTblExample;
import cn.com.lsy.product.lepao.model.mt.dao.MtDataTotalMapper;
import cn.com.lsy.product.lepao.model.mt.dao.MtEquipmentLogsMapper;
import cn.com.lsy.product.lepao.model.mt.dao.MtTotalDataMapper;
import cn.com.lsy.product.lepao.model.mt.entities.SelectStoreEnterInfoDto;
import cn.com.lsy.product.lepao.model.mt.entities.SelectStoreIncomeInfoDto;
import cn.com.lsy.product.lepao.service.IDataTotalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DataTotalService implements IDataTotalService {

    @Autowired
    MtTotalDataMapper mtTotalDataMapper;
    @Autowired
    LpDataTotalTblMapper lpDataTotalTblMapper;
    @Autowired
    MtDataTotalMapper mtDataTotalMapper;
    @Autowired
    MtEquipmentLogsMapper mtEquipmentLogsMapper;
    @Autowired
    LpStoreDataTotalTblMapper lpStoreDataTotalTblMapper;

    @Override
    public BigDecimal selectNewRegisterTotal(String startTime, String endTime) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("startTime", startTime);
        where.put("endTime", endTime);

        return mtTotalDataMapper.selectNewRegisterTotal(where);
    }

    @Override
    public BigDecimal selectEnterTotal(String startTime, String endTime, int storeId) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("startTime", startTime);
        where.put("endTime", endTime);
        where.put("storeId", storeId);

        return mtTotalDataMapper.selectEnterTotal(where);
    }

    @Override
    public BigDecimal selectDayCardEnterTotal(String startTime, String endTime, int storeId) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("startTime", startTime);
        where.put("endTime", endTime);
        where.put("storeId", storeId);

        return mtTotalDataMapper.selectDayCardEnterTotal(where);
    }

    @Override
    public BigDecimal selectMonthCardEnterTotal(String startTime, String endTime, int storeId) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("startTime", startTime);
        where.put("endTime", endTime);
        where.put("storeId", storeId);

        return mtTotalDataMapper.selectMonthCardEnterTotal(where);
    }

    @Override
    public BigDecimal selectCouponEnterTotal(String startTime, String endTime, int storeId) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("startTime", startTime);
        where.put("endTime", endTime);
        where.put("storeId", storeId);

        return mtTotalDataMapper.selectCouponEnterTotal(where);
    }

    @Override
    public BigDecimal selectNewMonthCardTotal(String startTime, String endTime) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("startTime", startTime);
        where.put("endTime", endTime);

        return mtTotalDataMapper.selectNewMonthCardTotal(where);
    }

    @Override
    public BigDecimal selectPaymentDeposit(String startTime, String endTime) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("startTime", startTime);
        where.put("endTime", endTime);

        return mtTotalDataMapper.selectPaymentDeposit(where);
    }

    @Override
    public BigDecimal selectRefundDeposit(String startTime, String endTime) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("startTime", startTime);
        where.put("endTime", endTime);

        return mtTotalDataMapper.selectRefundDeposit(where);
    }

    @Override
    public BigDecimal selectDepositBalance(String startTime, String endTime) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("startTime", startTime);
        where.put("endTime", endTime);

        return mtTotalDataMapper.selectDepositBalance(where);
    }

    @Override
    public BigDecimal selectRecharge(String startTime, String endTime) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("startTime", startTime);
        where.put("endTime", endTime);

        return mtTotalDataMapper.selectRecharge(where);
    }

    @Override
    public BigDecimal selectIncome(String startTime, String endTime, List<Integer> storeId) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("startTime", startTime);
        where.put("endTime", endTime);
        where.put("storeId", storeId);

        return mtTotalDataMapper.selectIncome(where);
    }

    @Override
    public BigDecimal selectDayCardIncome(String startTime, String endTime, int storeId) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("startTime", startTime);
        where.put("endTime", endTime);
        where.put("storeId", storeId);

        return mtTotalDataMapper.selectDayCardIncome(where);
    }

    @Override
    public BigDecimal selectMonthCardIncome(String startTime, String endTime) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("startTime", startTime);
        where.put("endTime", endTime);

        return mtTotalDataMapper.selectMonthCardIncome(where);
    }

    @Override
    public BigDecimal selectStoreMonthCardIncome(String startTime, String endTime, int storeId) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("startTime", startTime);
        where.put("endTime", endTime);
        where.put("storeId", storeId);

        return mtTotalDataMapper.selectStoreMonthCardIncome(where);
    }

    @Override
    public boolean updateStoreMonthCardIncome(Date time, int storeId, LpStoreDataTotalTbl param) {

        LpStoreDataTotalTblExample example = new LpStoreDataTotalTblExample();
        example.createCriteria().andTimesEqualTo(time).andStoreIdEqualTo(storeId);

        if (lpStoreDataTotalTblMapper.updateByExampleSelective(param, example) > 0) {

            return true;

        } else {

            return false;
        }
    }

    @Override
    public int delDataTotal(int id) {

        return lpDataTotalTblMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int addDataTotal(LpDataTotalTbl param) {

        return lpDataTotalTblMapper.insertSelective(param);
    }

    @Override
    public List<LpDataTotalTbl> selectDataTotal(Date time) {

        LpDataTotalTblExample example = new LpDataTotalTblExample();
        example.createCriteria().andTimesEqualTo(time);

        return lpDataTotalTblMapper.selectByExample(example);

    }

    @Override
    public List<LpDataTotalTbl> selectByPage(int start, int end, String startTime, String endTime) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("startTime", startTime);
        where.put("endTime", endTime);
        where.put("start", start);
        where.put("end", end);

        return mtDataTotalMapper.selectByPage(where);
    }

    @Override
    public int selectByCount(String startTime, String endTime) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("startTime", startTime);
        where.put("endTime", endTime);

        return mtDataTotalMapper.selectByCount(where);
    }

    @Override
    public BigDecimal incomeSum(String startTime, String endTime) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("startTime", startTime);
        where.put("endTime", endTime);

        return mtDataTotalMapper.incomeSum(where);
    }

    @Override
    public int selectUserEnterTotal(String startTime, String endTime) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("startTime", startTime);
        where.put("endTime", endTime);

        return mtEquipmentLogsMapper.selectUserEnterTotal(where);
    }

    @Override
    public int delStoreDataTotal(Date startTime, Date endTime) {

        LpStoreDataTotalTblExample example = new LpStoreDataTotalTblExample();
        example.createCriteria().andTimesGreaterThanOrEqualTo(startTime).andTimesLessThanOrEqualTo(endTime);

        return lpStoreDataTotalTblMapper.deleteByExample(example);

    }

    @Override
    public int insertStoreDataTotal(List<LpStoreDataTotalTbl> param) {

        return mtTotalDataMapper.insertStoreDataTotal(param);
    }

    @Override
    public List<LpDataTotalTbl> selectDataTotalList(int pageSize) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("pageSize", pageSize);

        return mtDataTotalMapper.selectList(where);
    }

    @Override
    public List<LpStoreDataTotalTbl> selectStoreDataTotal(int storeId, int pageSize) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("pageSize", pageSize);
        where.put("storeId", storeId);

        return mtDataTotalMapper.selectStoreDataTotal(where);
    }

    @Override
    public BigDecimal selectStoreRechargeIncome(String startTime, String endTime, int storeId) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("startTime", startTime);
        where.put("endTime", endTime);
        where.put("storeId", storeId);

        return mtTotalDataMapper.selectStoreRechargeIncome(where);
    }

    @Override
    public int selectStoreMonthCardNum(String startTime, String endTime, int storeId) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("startTime", startTime);
        where.put("endTime", endTime);
        where.put("storeId", storeId);

        return mtTotalDataMapper.selectStoreMonthCardNum(where);
    }

    @Override
    public int selectStoreDayCardNum(String startTime, String endTime, int storeId) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("startTime", startTime);
        where.put("endTime", endTime);
        where.put("storeId", storeId);

        return mtTotalDataMapper.selectStoreDayCardNum(where);
    }

    @Override
    public List<SelectStoreIncomeInfoDto> selectStoreIncomeInfo(String startTime, String endTime) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("startTime", startTime);
        where.put("endTime", endTime);

        List<SelectStoreIncomeInfoDto> list = mtDataTotalMapper.selectStoreIncomeInfo(where);

        return list;
    }

    @Override
    public List<SelectStoreEnterInfoDto> selectStoreEnterInfo(String startTime, String endTime) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("startTime", startTime);
        where.put("endTime", endTime);

        return mtDataTotalMapper.selectStoreEnterInfo(where);
    }
}
